#include <stdio.h>

int fib(int size)
{
  int i;
  int a = 0;
  int b = 1;
  int prev;
  int result=0;

  for (i = 0; i < size; i++) {
        prev = a;
        a = b;
        b = prev + b;

	printf(" %d", b);
  }
  printf("\n");
  return result;
}

int fibEvenSum(int max)
{
  int i;
  int a = 0;
  int b = 1;
  int prev;
  int result=0;

  for (i = 0; ; i++) {
        prev = a;
        a = b;
        b = prev + b;

	if ( b%2 != 0)
		continue;
	if (b >= max)
		break;
	result += b;
     //   printf("fib(%d) = %d \n", i, b);
  }
  return result;
}

void main()
{
  int result;

  fib(10);
  result = fibEvenSum(4000000);
  printf("result=%d \n", result);
}
